package mobile.game.common.support;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import mobile.game.core.Port;
import mobile.game.core.Service;

public class ClassManager {
	
	private static ClassManager classManager = new ClassManager();

	public static ClassManager getMe() {
		return classManager;
	}
	
	
	private Map<String, Port> mapPort = new ConcurrentHashMap<String, Port>();
	
	private Map<String, Service> mapService = new ConcurrentHashMap<String, Service>();
	
	public void addPort(Port port) {
		mapPort.put(port.getId().toString(), port);
	}
	
	public void addService(Service serv) {
		mapService.put(serv.getName(), serv);
	}
	
	/**
	 * 通过类型查找
	 * @param type
	 * @return
	 */
	public List<Port> getPortByType(String type) {
		List<Port> list = new ArrayList<Port>();
		
		for (Map.Entry<String, Port> entry : mapPort.entrySet()) {
			if (entry.getValue().getClass().getSimpleName().equals(type) ) {
				list.add(entry.getValue());
			}
		}
		
		return list;
	}
	
	/**
	 * 通过名字查找
	 * @param name
	 * @return
	 */
	public Port getPortById(String name) {
		return mapPort.get(name);
	}
	
}
